#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：zhcx-service-test 
@File    ：initialize_strategy_service.py
@Author  ：关依林
@Date    ：2023/7/17 23:28 
'''
import os
from utils.mysqlUtils.db_utils import DB
from common.dir_config import ConfigHandler
from utils.readFileUtils.yamlControl import GetYamlData
from testcases.ProductGrading_Strategy.public_dispatch_way import *
from utils.logging_tool.log_control import *


class PolicyConditionMethod:

    def __init__(self,categoryId):
        self.categoryId = str(categoryId)
        self.strategyConfiguration = GetYamlData(file_dir=ConfigHandler.strategy_dir + "strategy_case03.yaml").get_yaml_data()

    def strategyDataVerify(self):

        name = self.strategyConfiguration["name"]
        categoryId = int(self.strategyConfiguration["category_id"].replace("$categoryId",self.categoryId))
        dbNameProduct = self.strategyConfiguration["db_name1"]
        dbNameStrategy = self.strategyConfiguration["db_name2"]
        dbNameCategory = self.strategyConfiguration["db_name3"]
        conditionSqlSet = self.strategyConfiguration["sql"]
        comparison = self.strategyConfiguration["comparison"]

        # useLogHandler("INFO").info("开始执行策略======================>" + name)
        # messageList = getStrategyRule(categoryId)

        mysqlCursorProduct = connectMysql(dbNameProduct)
        mysqlCursorCategory = connectMysql(dbNameCategory)
        if messageList:
            strategySku = []
            for condition in messageList:
                if not strategySku:
                    strategySku = processingLogicTest(conditionSqlSet,condition,mysqlCursorProduct, mysqlCursorCategory, strategySku)
                else:
                    strategySku = processingLogicTest(conditionSqlSet,condition,mysqlCursorProduct, mysqlCursorCategory, strategySku)
        else:
            # useLogHandler("ERROR").error("策略：" + name + ",没有配置策略条件,校验异常...")
            return

        strategyResult = getStrategyResult(comparison, categoryId)
        strategySku = set(strategySku)
        strategyResult = set(strategyResult)
        verifyResult = tuple(strategySku - strategyResult)
        verifyReverseResult = tuple(strategyResult - strategySku)

        # for err in verifyResult:
        #     # useLogHandler("ERROR").error("sku：" + err[0] + ",该sku与策略服务执行结果不匹配")
        # # useLogHandler("INFO").info("结束执行策略======================>" + name)
        # return verifyResult



if __name__ == '__main__':
    PolicyConditionMethod(categoryId=92).strategyDataVerify()
    # getBasicsData("sku,last_buy_price")